package com.xingchi.tornado.dict.handler;

import com.xingchi.tornado.core.utils.RedisUtils;
import com.xingchi.tornado.dict.model.DictMetadata;
import com.xingchi.tornado.dict.service.DictStorageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.List;

/**
 * 缓存后置处理器
 *
 * @author xiaoya
 * @date 2025/7/2 19:17
 */
@Slf4j
@RequiredArgsConstructor
public class DictRefreshCachePostProcessor implements DictRefreshPostProcessor{

    private final RedisUtils redisUtils;
    private final ThreadPoolTaskExecutor defaultExecutorService;
    private final DictStorageService dictStorageService;

    /**
     * 执行缓存处理
     * 缓存key设计：
     *      前缀：{@link com.xingchi.tornado.dict.constants.DictConstants#DICT_REDIS_STORAGE_KEY}
     * 采用hash结构存储
     */
    @Override
    public void postProcessor(final List<DictMetadata> dictMetadataList) {
        // 刷新完成之后更新缓存
        defaultExecutorService.submit(dictStorageService::refreshCache);
    }

}
